// GIS.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "Vertex.h"
#include "GraphDescription.h"
#include "GraphDescriptionReader.h"
#include <time.h>
#include "FlowGenerator.h"

int _tmain(int argc, _TCHAR* argv[])
{
	int t =0;
	GraphDescription graph;
	string file;

	std::cout << "Program menu:\n1 - Generate graph description\n2 - Full scan\n3 - Shortest first\n4 - Hybridization\n5 - Flow based scan\nexit - end program\n";
	std::cin >> file;

	while (file.compare("exit") != 0) //wykonuj program az uzytkownik nie wpisze exit
	{
		if (file.compare("1") == 0)
		{
				FlowGenerator fg = FlowGenerator();
				GraphDescription gd = fg.generateGraph(50000, 10, 0.5); //internal nodes, base propability 					 
				ofstream outputFile; 
				outputFile.open("generated.txt");
				gd.printGrpah(outputFile);	   
				outputFile.close();
		}
		else if (file.compare("2") == 0){
			std::cout << "Write description file name:\n";
			std::cin >> file;
			t = time(NULL);

			graph = GraphDescription();
			graph.readGraphDescription(file); // wczytaj graf
			//graph.printVertexes();
			if (graph.verifyGraphDescription()) //sprawdz jego poprawnosc
			{
				try
				{
					t = time(NULL);
					std::cout << "\n\nFull scan method:\n";
					graph = GraphDescription();
					graph.readGraphDescription(file); 
					graph.setStartRoute();
					graph.describeVertexes(&graph.getVertexList()["S"]);
					graph.findRoutes("T");
					std::cout << "Time efficiency: ";
					std::cout << time(NULL) - t;
					t = time(NULL);
				}
				catch (...)
				{
					std::cout << "Cycle detected - bad description file!\n";
				}
			}
			else
				std::cout << "Bad description file!\n";
		}
			else if (file.compare("3") == 0){
			std::cout << "Write description file name:\n";
			std::cin >> file;
			t = time(NULL);
			graph = GraphDescription();
			graph.readGraphDescription(file); // wczytaj graf
			//graph.printVertexes();
			if (graph.verifyGraphDescription()) //sprawdz jego poprawnosc
			{
				try
				{

					t = time(NULL);
					std::cout << "\n\nShortest paths first:\n";
					graph = GraphDescription();
					graph.readGraphDescription(file);
					graph.shortestPaths();
					std::cout << "Time efficiency: ";
					std::cout << time(NULL) - t;
					t = time(NULL);
				}
				catch (...)
				{
					std::cout << "Cycle detected - bad description file!\n";
				}
			}
			else
				std::cout << "Bad description file!\n";
		}
		else if (file.compare("4") == 0){
			std::cout << "Write description file name:\n";
			std::cin >> file;
			t = time(NULL);

			graph = GraphDescription();
			graph.readGraphDescription(file); // wczytaj graf
			//graph.printVertexes();
			if (graph.verifyGraphDescription()) //sprawdz jego poprawnosc
			{
				try
				{
					t = time(NULL);
					std::cout << "\n\nShortest paths with hybridization:\n";
					graph = GraphDescription();
					graph.readGraphDescription(file);
					graph.shortestPathsWithHybridization();
					std::cout << "Time efficiency: ";
					std::cout << time(NULL) - t;
					t = time(NULL);
				}
				catch (...)
				{
					std::cout << "Cycle detected - bad description file!\n";
				}
			}
		}
		else if (file.compare("5") == 0){
			std::cout << "Write description file name:\n";
			std::cin >> file;
			t = time(NULL);

			graph = GraphDescription();
			graph.readGraphDescription(file); // wczytaj graf
			//graph.printVertexes();
			if (graph.verifyGraphDescription()) //sprawdz jego poprawnosc
			{
				try
				{
					std::cout << "Flow method:\n";	
					graph.setStartRouteFlowMethod();
					std::cout << "Time efficiency: ";
					std::cout << time(NULL) - t;
					t = time(NULL);
				}
				catch (...)
				{
					std::cout << "Cycle detected - bad description file!\n";
				}
			}
		}
		std::cout << "\n\n";
	std::cout << "Program menu:\n1 - Generate graph description\n2 - Full scan\n3 - Shortest first\n4 - Hybridization\n5 - Flow based scan\nexit - end program\n";
		std::cin >> file;

	}
	return 0;
}


